﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApC3DSnapshotNodeData
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

internal class CApC3DSnapshotNodeData
{
  internal static string CurrentViewName = "Default view";
  internal static string StartOperationViewName = "Start operation view";
  private TxSnapshot m_snapshot;
  private SnapshotType m_snapshotType = SnapshotType.Existed;
  private string m_snapshotName;
  private string m_snapshotDisplayName;

  internal CApC3DSnapshotNodeData(TxSnapshot snapshot)
  {
    this.m_snapshot = snapshot;
    this.UpdateNames();
  }

  internal CApC3DSnapshotNodeData(CApC3DSnapshotComboItem snapshotItem)
  {
    this.m_snapshot = snapshotItem.Snapshot;
    this.m_snapshotType = snapshotItem.SnapshotType;
    this.UpdateNames();
  }

  internal CApC3DSnapshotNodeData(SnapshotType snapshotType)
  {
    this.m_snapshotType = snapshotType;
    this.UpdateNames();
    this.Create();
  }

  internal CApC3DSnapshotNodeData(string name, string displayName)
  {
    this.m_snapshotType = !(name == CApC3DSnapshotNodeData.CurrentViewName) ? (!(name == CApC3DSnapshotNodeData.StartOperationViewName) ? SnapshotType.NotExisted : SnapshotType.StartOperationView) : SnapshotType.CurrentView;
    this.UpdateNames(name);
  }

  internal TxSnapshot Snapshot
  {
    get => this.m_snapshot;
    set
    {
      if (!TxSnapshot.op_Equality(this.m_snapshot, (ITxObject) null))
        return;
      this.m_snapshot = value;
      this.UpdateNames();
    }
  }

  internal string Name => this.m_snapshotName;

  internal string DisplayName => this.m_snapshotDisplayName;

  internal bool DoesSnapshotExist => this.m_snapshotType != SnapshotType.NotExisted;

  internal bool IsStartOperationView => this.m_snapshotType == SnapshotType.StartOperationView;

  internal bool IsCurrentView => this.m_snapshotType == SnapshotType.CurrentView;

  internal void Set(CApC3DSnapshotComboItem snapshotItem)
  {
    this.m_snapshot = snapshotItem.Snapshot;
    this.m_snapshotType = snapshotItem.SnapshotType;
    this.UpdateNames();
  }

  internal void Create()
  {
    this.m_snapshot = TxApplication.ActiveDocument.PhysicalRoot.CreateSnapshot(new TxSnapshotCreationData()
    {
      Name = this.m_snapshotDisplayName
    });
  }

  internal void CreateStartOperationView(CApC3DProcessNodeData processNode)
  {
    if (!this.IsStartOperationView)
      return;
    this.UpdateNames(processNode);
    this.Create();
  }

  internal void DeleteStartOperationView()
  {
    if (!this.IsStartOperationView || !TxSnapshot.op_Inequality(this.Snapshot, (ITxObject) null))
      return;
    this.m_snapshot.Delete();
    this.m_snapshot = (TxSnapshot) null;
  }

  private void UpdateNames()
  {
    if (TxSnapshot.op_Inequality(this.m_snapshot, (ITxObject) null))
    {
      this.m_snapshotDisplayName = this.m_snapshot.Name;
      this.m_snapshotName = this.m_snapshot.Name;
    }
    else
    {
      this.m_snapshotDisplayName = "";
      this.m_snapshotName = "";
      if (this.m_snapshotType == SnapshotType.CurrentView)
      {
        this.m_snapshotDisplayName = CApC3DUtils.GetResourceManager().GetString("CREATE_3D_DOCUMENTATION_CURRENT_VIEW");
        this.m_snapshotName = CApC3DSnapshotNodeData.CurrentViewName;
      }
      else
      {
        if (this.m_snapshotType != SnapshotType.StartOperationView)
          return;
        this.m_snapshotDisplayName = CApC3DUtils.GetResourceManager().GetString("CREATE_3D_DOCUMENTATION_START_OPERATION_VIEW");
        this.m_snapshotName = CApC3DSnapshotNodeData.StartOperationViewName;
      }
    }
  }

  private void UpdateNames(string name)
  {
    this.UpdateNames();
    if (this.m_snapshotType != SnapshotType.NotExisted)
      return;
    this.m_snapshotDisplayName = name;
  }

  private void UpdateNames(CApC3DProcessNodeData processNode)
  {
    this.UpdateNames();
    if (this.m_snapshotType != SnapshotType.StartOperationView || processNode == null)
      return;
    this.m_snapshotDisplayName = $"{this.m_snapshotDisplayName} - {((ITxObject) processNode.NodeObject).Name}";
  }

  public override string ToString() => this.DisplayName;
}
